package tongwentongshu.com.app.presenter;

import android.support.v4.util.ArrayMap;

import java.util.Map;

import tongwentongshu.com.app.bean.MyShareBean;
import tongwentongshu.com.app.bean.ShareDetailsBean;
import tongwentongshu.com.app.contract.MyShareDetailsContract;
import tongwentongshu.com.app.db.Cache;
import tongwentongshu.com.app.network.ResponseSubscriber;
import tongwentongshu.com.app.update.UpdateFractory;

/**
 * Created by XiongBin on 2017/7/20.
 */

public class MyShareDetailsPresenter implements MyShareDetailsContract.Presenter {
    MyShareDetailsContract.View myShareView;
    private Map<String, String> map;

    public MyShareDetailsPresenter(MyShareDetailsContract.View myShareView) {
        this.myShareView = myShareView;
    }

    @Override
    public void initShareDetails(String bookid) {
        map = new ArrayMap<>();
        map.put("token", Cache.getToken());
        map.put("bookid", bookid);

        UpdateFractory.getBuild()
                .name("MyShareDetailCall")
                .map(map)
                .build()
                .execute(new ResponseSubscriber<ShareDetailsBean>() {

                    @Override
                    public void onFailure(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onSuccess(ShareDetailsBean myshare, String msg) {
                        myShareView.onSuccess(myshare);
                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }
                });
    }
}
